/**
 * 
 */
package com.et114.modules.products.cellphone.action;


import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.et114.components.simpletable.DataList;
import com.et114.core.action.BaseDispatchAction;
import com.et114.core.common.AppContext;
import com.et114.core.common.CONST;
import com.et114.core.utility.ArgumentTokenizer;
import com.et114.core.utility.NumberUtils;
import com.et114.core.utility.SQLParser;
import com.et114.core.utility.Sentence;
import com.et114.core.utility.StringPool;
import com.et114.modules.products.base.ProImage;
import com.et114.modules.products.base.ProImageServiceImpl;
import com.et114.modules.products.brands.services.BrandServiceImpl;
import com.et114.modules.products.brands.vo.Brand;
import com.et114.modules.products.commons.Const;
//import com.et114.modules.products.commons.Context;
import com.et114.modules.products.commons.PorJsonObj;
import com.et114.modules.products.cellphone.action.CellPhoneForm;
import com.et114.modules.products.cellphone.services.CellPhoneServiceImpl;
import com.et114.modules.products.cellphone.vo.CellPhone;
import com.et114.modules.products.params.ParamServiceImpl;
import com.et114.modules.products.params.ParamType;
import com.et114.modules.products.procontent.services.ProContentServiceImpl;
import com.et114.modules.products.procontent.vo.ProContent;
//import com.et114.modules.products.search.SearchVo;
import com.et114.modules.products.services.ProPropertySetImp;
import com.et114.modules.products.supplier.services.SupplierServiceImpl;
import com.et114.modules.products.supplier.vo.ProSuppliers;
import com.et114.modules.products.vo.PropertyData;
import com.et114.modules.system.dictionary.DictionaryCache;
import com.et114.modules.system.dictionary.vo.BizOption;

/*
 * @author guanhw
 */
public class CellPhoneAction extends BaseDispatchAction {
	private final static String SEARCH_ADV = "2" ; 
	
	//mod //2010-12-14 合并sql 
	
	
	@ SuppressWarnings ( "unchecked" )
	public  ActionForward getCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		long ct = System.currentTimeMillis ( ) ; 
		//DIC 
		List< BizOption >  bssOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_CP_CellPhoneBrands_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "brandsOps" , bssOps ) ;
		
		List< BizOption >  bproOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_PUB_STATUS_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bproOps" , bproOps ) ;
		
		//DIC 
		List< BizOption >  bcolorOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_Color_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bcolorOps" , bcolorOps ) ;

		List< BizOption >  bdssOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_SERVICE_PLAN_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bdssOps" , bdssOps ) ;

		
		BrandServiceImpl brandServiceImpl = ( BrandServiceImpl ) getBean( "brandServiceImpl" ) ;
		Brand brand = new Brand(  ) ; 
		brand.setProType ( Const.PRO_TYPE_CELLPHONE ) ; 
		brand.setWorkflg ( Const.COMMON_STATUS_ENA ) ;
		List brands = brandServiceImpl.getBrandList ( brand ) ; 
		request.setAttribute ( "brands" , brands ) ; 
		
		SupplierServiceImpl ssbean = ( SupplierServiceImpl )getBean ( "supplierServiceImpl" ) ;
		ProSuppliers psvo = new ProSuppliers( ) ; 
		psvo.setSupplierPros ( StringPool.COMMA + Const.PRO_TYPE_CELLPHONE + StringPool.COMMA ) ; 
		psvo.setWorkFlg ( String.valueOf ( Const.COMMON_STATUS_ENA ) ) ;
		List< ProSuppliers > proTypes = ssbean.querySuppliersList ( psvo ) ; 
		request.setAttribute ( "proTypes" , proTypes ) ;
		
		ProImageServiceImpl pisi = ( ProImageServiceImpl ) getBean( "proImageServiceImpl" ) ;

		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl ) getBean ( "cellPhoneServiceImpl" );
		ProContentServiceImpl proContentServiceImpl = ( ProContentServiceImpl ) getBean ( "proContentServiceImpl" );
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form;
		CellPhone cellPhone = new CellPhone ( );
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 
		
		Long sdid = cellPhoneForm.getProId ( ) ; 
		if ( sdid != null && sdid.longValue ( ) != 0  ) { // load one
			request.setAttribute ( "searchVo" , cellPhone ) ;
			//
			cellPhone = sss.getCellPhoneById ( sdid ) ; 
			request.setAttribute ( "cellPhone" , cellPhone ) ;
			
			//
			ProContent pcontent = proContentServiceImpl
								.getProContent ( new ProContent ( Byte
										.valueOf ( Const.PRO_TYPE_CELLPHONE ) , sdid ) );
			if ( pcontent != null )
				request.setAttribute ( "content" , pcontent );
			return mapping.findForward ( "cellPhone" ) ; 
		}
		else { //loads
			//PARAM
			ProPropertySetImp proPropertySetImp = ( ProPropertySetImp )getBean ( "proPropertySetImp" ) ; 
			Map< String , String > paramsMap = new HashMap< String , String > () ; 
			String params = cellPhoneForm.getParams ( ) ;
			String sql = proPropertySetImp.generateSql ( params ) ; 
			

			if ( !StringUtils.isEmpty ( params ) && !StringUtils.isBlank ( params )  ) {
				int flg = 0 ;
				ArgumentTokenizer ats = new ArgumentTokenizer( params , ';' ) ;
				while (  ats.hasNext ( ) ) {
					String ass = ats.next ( ) ; 
					ArgumentTokenizer as = new ArgumentTokenizer( ass , ':' ) ;
					flg ++ ; 
					while( as.hasNext ( ) ) {
						String key = as.next ( ) ; 
						String value = as.next ( ) ; 
						paramsMap.put ( key , value )	 ;
					}
				}
			}	
			
		
			//generate form
			
			ParamType vo = new ParamType () ; 
		
			//BIS
			
			//生成查询表单
			long pst = System.currentTimeMillis ( ) ; 
			ParamServiceImpl psi = ( ParamServiceImpl )getBean( "paramServiceImpl" ) ; 

			List< ParamType > paramTypesTmp = new ArrayList< ParamType > ( ) ; //psi.getParamTypeList (  vo ) ; 		
			vo.setWorkflg ( Const.COMMON_STATUS_ENA ) ; 
			vo.setGlobalKey ( String.valueOf ( Const.PRO_TYPE_CELLPHONE ) ) ;
			//vo.setSearch4h ( true ) ; 
			List< ParamType > paramTypeRoots = psi.getRootParamType( vo ) ;
			for ( ParamType paramType : paramTypeRoots ) { 
				if ( paramType.getWorkflg ( ) == Const.COMMON_STATUS_ENA ) {
					List< ParamType  > spt = paramType.getEnableFormChilds4h ( ) ;
					if ( spt != null && spt.size ( ) > 0 )
						paramTypesTmp.add ( paramType ) ;
				}
			}
			request.setAttribute ( "paramvo" , vo ) ;
			request.setAttribute ( "paramTypes" , paramTypesTmp ) ;
			logger.info ( "cell phone generate param search time:" + ( System.currentTimeMillis ( ) - pst ) ) ;
			
			//初始
					
			DataList dl = null ; 
			List< CellPhone >  allCellphones = null ; 
			
			//set order by
			if ( Boolean.valueOf ( true ).equals ( cellPhone.getSdTj ( ) )
					&& Boolean.valueOf ( true ).equals ( cellPhone.getSdCx ( ) ) ) {
				cellPhone.setOrderStr ( null ) ; 
			}				
			else {
				if ( Boolean.valueOf ( true ).equals ( cellPhone.getSdTj ( ) ) ) 
						cellPhone.setOrderStr ( " e.tjOrder asc ,  e.CRTTIME DESC  " ) ; 
				if ( Boolean.valueOf ( true ).equals ( cellPhone.getSdCx ( ) ) ) 
						cellPhone.setOrderStr ( " e.cxOrder asc ,  e.CRTTIME DESC  " ) ;  
			}
			
			if (  !StringUtils.isEmpty ( sql ) && !StringUtils.isBlank ( sql )  ) {
				sql = sql
						+ " AND e.proId = SUBSTRING( ( GLOBAL_KEY )   ,3 , LENGTH( GLOBAL_KEY ) )";
				
				cellPhone.setProIdSql ( sql ) ; 
				
				allCellphones = sss.getCellPhones4Manager ( cellPhone );
				
				int count = sss.countgetCellPhones ( cellPhone ).intValue ( );
				int pn = cellPhone.getPageNum ( );
				int ps = cellPhone.getPageSize ( );
				if ( ( pn - 1 ) * ps  >= allCellphones.size ( ) ) 
					pn = 1 ; 
				
				dl = new DataList ( allCellphones.subList (
						( ( pn - 1 ) * ps ) , ( ( pn + 1 ) * ps > allCellphones
								.size ( ) ? allCellphones.size ( ) : ( pn + 1 )
								* ps ) ) , count , ps , pn );
				
			}
			else {
				allCellphones = sss.getCellPhones4Manager ( cellPhone );
				
				int count = sss.countgetCellPhones ( cellPhone ).intValue ( );
				int pn = cellPhone.getPageNum ( );
				int ps = cellPhone.getPageSize ( );
				if ( ( pn - 1 ) * ps  >= allCellphones.size ( ) ) 
					pn = 1 ; 
				dl = new DataList ( allCellphones.subList (
						( ( pn - 1 ) * ps ) , ( ( pn + 1 ) * ps >= allCellphones
								.size ( ) ? allCellphones.size ( ) : ( pn + 1 )
								* ps ) ) , count , ps , pn );
			}
		

				
			List< Long > proIdArray = new ArrayList< Long >( ); 

			if ( dl != null ) {
				List< CellPhone > cps = dl.getNowlist ( ) ;
				
				proIdArray = new ArrayList< Long >( ) ; 
				if (  proIdArray.size ( ) == 0 ) {
					for ( CellPhone cp : cps ) { 
						proIdArray.add ( cp.getProId ( ) ) ; 
					}					
				}
			
		
				if ( proIdArray.size ( ) > 0 ) {
					Long[] proIds = new Long [ proIdArray.size ( ) ]   ;

					proIdArray.toArray ( proIds) ;						
					ProImage proImage = new ProImage( ) ; 
					proImage.setProIds ( proIds ) ; 
					proImage.setProType ( Const.PRO_TYPE_CELLPHONE ) ;
					List < ProImage > pis = pisi
							.getProImageColorsByProIdsCacheModel ( proImage );
					List proImageColors = null ; 
					for ( CellPhone cp : cps ) { 
						cp.setProImageColors ( null ) ; 
						proImageColors = new ArrayList( ) ; 
						for ( java.util.Iterator < ProImage > iter = pis
								.iterator ( ) ; iter.hasNext ( ) ; ) {
							proImage = iter.next ( );
							if ( proImage.getProId ( )
									.equals ( cp.getProId ( ) ) ) {
								proImageColors.add ( proImage );
							}
						}		
						cp.setProImageColors ( proImageColors ) ;
					}
				}
			

				
			
				request.setAttribute ( "dl" , dl ) ;
			}
			
			
			if (  allCellphones != null && allCellphones.size ( ) > 0  ) {
				PropertyData ppd = new PropertyData( ) ; 
				ppd.setGlobalKey ( Const.PRO_TYPE_CELLPHONE + StringPool.DASH ) ; 
				List< PropertyData > pds  = proPropertySetImp.selectProperty4Search3( ppd ) ; 
				
				
				if ( pds != null ) {
					Map < String , String > itemKeys = new HashMap < String , String > ( pds.size ( ) );
					for ( PropertyData pd : pds ) {
						for ( CellPhone cp : allCellphones ) {
							if ( ( Const.PRO_TYPE_CELLPHONE + StringPool.DASH + cp
									.getProId ( ) )
									.equals ( pd.getGlobalKey ( ) ) )
								itemKeys.put ( pd.getItemKey ( ) , pd
										.getItemKey ( ) );
						}
						
					}
					request.setAttribute ( "itemKeys" , itemKeys );
				} else
					request.setAttribute ( "itemKeys" ,
							new HashMap < String , String > ( ) );

			}

				 	
			request.setAttribute ( "params" , params ) ;
			request.setAttribute ( "searchVo" , cellPhone ) ; 
			request.setAttribute ( "paramsMap" , paramsMap ) ;
			
			logger.info ( "generate CELL PHONE generateAdvParamForm time:" + ( System.currentTimeMillis ( ) - ct ) ) ;			
			return mapping.findForward ( "cellPhones" ) ; 
		}
		
	} 

	/*
	@ SuppressWarnings ( "unchecked" )
	public  ActionForward getCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		long ct = System.currentTimeMillis ( ) ; 
		//DIC 
		List< BizOption >  bssOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_CP_CellPhoneBrands_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "brandsOps" , bssOps ) ;
		
		List< BizOption >  bproOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_PUB_STATUS_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bproOps" , bproOps ) ;
		
		//DIC 
		List< BizOption >  bcolorOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_Color_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bcolorOps" , bcolorOps ) ;

		List< BizOption >  bdssOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_SERVICE_PLAN_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bdssOps" , bdssOps ) ;

		
		BrandServiceImpl brandServiceImpl = ( BrandServiceImpl ) getBean( "brandServiceImpl" ) ;
		Brand brand = new Brand(  ) ; 
		brand.setProType ( Const.PRO_TYPE_CELLPHONE ) ; 
		List brands = brandServiceImpl.getBrandList ( brand ) ; 
		request.setAttribute ( "brands" , brands ) ; 
		
		SupplierServiceImpl ssbean = ( SupplierServiceImpl )getBean ( "supplierServiceImpl" ) ;
		ProSuppliers psvo = new ProSuppliers( ) ; 
		psvo.setSupplierPros ( StringPool.COMMA + Const.PRO_TYPE_CELLPHONE + StringPool.COMMA ) ; 
		psvo.setWorkFlg ( String.valueOf ( Const.COMMON_STATUS_ENA ) ) ;
		List< ProSuppliers > proTypes = ssbean.querySuppliersList ( psvo ) ; 
		request.setAttribute ( "proTypes" , proTypes ) ;
		
		ProImageServiceImpl pisi = ( ProImageServiceImpl ) getBean( "proImageServiceImpl" ) ;

		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl ) getBean ( "cellPhoneServiceImpl" );
		ProContentServiceImpl proContentServiceImpl = ( ProContentServiceImpl ) getBean ( "proContentServiceImpl" );
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form;
		CellPhone cellPhone = new CellPhone ( );
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 
		
		Long sdid = cellPhoneForm.getProId ( ) ; 
		if ( sdid != null && sdid.longValue ( ) != 0  ) { // load one
			request.setAttribute ( "searchVo" , cellPhone ) ;
			//
			cellPhone = sss.getCellPhoneById ( sdid ) ; 
			request.setAttribute ( "cellPhone" , cellPhone ) ;
			
			//
			ProContent pcontent = proContentServiceImpl
								.getProContent ( new ProContent ( Byte
										.valueOf ( Const.PRO_TYPE_CELLPHONE ) , sdid ) );
			if ( pcontent != null )
				request.setAttribute ( "content" , pcontent );
			return mapping.findForward ( "cellPhone" ) ; 
		}
		else { //loads
			//PARAM
			ProPropertySetImp proPropertySetImp = ( ProPropertySetImp )getBean ( "proPropertySetImp" ) ; 
			Map< String , String > paramsMap = new HashMap< String , String > () ; 
			String params = cellPhoneForm.getParams ( ) ;
			//String sql = proPropertySetImp.generateSql2 ( params ) ; 
			
		
			String base = "SELECT  distinct( GLOBAL_KEY ) as globalKey FROM " +
					" B_PROPERTYDATA WHERE  ITEM_KEY =";
			String sql = null  ; 
			if ( !StringUtils.isEmpty ( params ) && !StringUtils.isBlank ( params )  ) {
				int flg = 0 ; 
				ArgumentTokenizer ats = new ArgumentTokenizer( params , ';' ) ; 
				while (  ats.hasNext ( ) ) {
					String ass = ats.next ( ) ; 
					ArgumentTokenizer as = new ArgumentTokenizer( ass , ':' ) ;
					while( as.hasNext ( ) ) {
						String key = as.next ( ) ; 
						String value = as.next ( ) ; 
						paramsMap.put ( key , value )	 ;
						flg ++ ; 
						
						if ( flg == 1 )
							sql = base + "'" + SQLParser.transactSQLInjection (  key ) + "'";
						else
							sql = base   + "'" + SQLParser.transactSQLInjection (  key ) + "'"
									+ " AND GLOBAL_KEY IN ( " + sql + ")";
					}
				}
			}	
			
	
			//generate form
			
			ParamType vo = new ParamType () ; 
		
			//BIS
			
			//生成查询表单
			long pst = System.currentTimeMillis ( ) ; 
			ParamServiceImpl psi = ( ParamServiceImpl )getBean( "paramServiceImpl" ) ; 

			List< ParamType > paramTypesTmp = new ArrayList< ParamType > ( ) ; //psi.getParamTypeList (  vo ) ; 		
			vo.setWorkflg ( Const.COMMON_STATUS_ENA ) ; 
			vo.setGlobalKey ( String.valueOf ( Const.PRO_TYPE_CELLPHONE ) ) ;
			List< ParamType > paramTypeRoots = psi.getRootParamType( vo ) ;
			for ( ParamType paramType : paramTypeRoots ) { 
				if ( paramType.getWorkflg ( ) == Const.COMMON_STATUS_ENA )
					paramTypesTmp.addAll ( paramType.getEnableFormChilds4h ( ) ) ;
			}
			request.setAttribute ( "paramvo" , vo ) ;
			request.setAttribute ( "paramTypes" , paramTypeRoots ) ;
			logger.info ( "cell phone generate param search time:" + ( System.currentTimeMillis ( ) - pst ) ) ;
			
			//初始
					
			DataList dl = null ; 
			List< CellPhone >  allCellphones = null ; 
			List< Long > proIdArray = new ArrayList< Long >( ); 
			
			if (  !StringUtils.isEmpty ( sql ) && !StringUtils.isBlank ( sql )  ) {
				Map paramsVo = new HashMap( ) ; 
				paramsVo.put ( "GLOBAL" , String.valueOf ( Const.PRO_TYPE_CELLPHONE )   ) ; 
				paramsVo.put ( "PARAMS" , sql ) ; 
				
				long st = System.currentTimeMillis ( ) ; 
				
				List< PropertyData > pds =  proPropertySetImp.selectProperty4Search ( paramsVo ) ; 
				for ( PropertyData pd : pds ) {
					String globalKey = pd.getGlobalKey ( ) ; 
					proIdArray.add ( Long.valueOf ( globalKey.split (  StringPool.DASH  )[ 1 ] ) ) ; 
				}
				logger.info ( "generate search time:" + ( System.currentTimeMillis ( ) - st ) ) ;
			}
			else {
				allCellphones = sss.getCellPhones4 ( cellPhone );
				
				int count = sss.countgetCellPhones ( cellPhone ).intValue ( );
				int pn = cellPhone.getPageNum ( );
				int ps = cellPhone.getPageSize ( );
				if ( ( pn - 1 ) * ps  >= allCellphones.size ( ) ) 
					pn = 1 ; 
				dl = new DataList ( allCellphones.subList (
						( ( pn - 1 ) * ps ) , ( ( pn + 1 ) * ps >= allCellphones
								.size ( ) ? allCellphones.size ( ) : ( pn + 1 )
								* ps ) ) ,
				count , ps , pn );
			}
			
			if ( proIdArray.size ( ) >0  ) {
				//
				Long[] proIds = new Long [ proIdArray.size ( ) ]   ;
				proIdArray.toArray ( proIds) ;
				cellPhone.setProIds ( proIds ) ; 
				
				
				allCellphones = sss.getCellPhones4 ( cellPhone );
				
				int count = sss.countgetCellPhones ( cellPhone ).intValue ( );
				int pn = cellPhone.getPageNum ( );
				int ps = cellPhone.getPageSize ( );
				if ( ( pn - 1 ) * ps  >= allCellphones.size ( ) ) 
					pn = 1 ; 
				
				dl = new DataList ( allCellphones.subList (
						( ( pn - 1 ) * ps ) , ( ( pn + 1 ) * ps > allCellphones
								.size ( ) ? allCellphones.size ( ) : ( pn + 1 )
								* ps ) ) , count , ps , pn );
				
			}
			
			

				
		
			if ( dl != null ) {
				List< CellPhone > cps = dl.getNowlist ( ) ;
				List< String > globalKeys = new ArrayList< String > ( 5 ) ; 
				
				proIdArray = new ArrayList< Long >( ) ; 
				if (  proIdArray.size ( ) == 0 ) {
					for ( CellPhone cp : cps ) { 
						proIdArray.add ( cp.getProId ( ) ) ; 
					}					
				}
			
		
				if ( proIdArray.size ( ) > 0 ) {
					Long[] proIds = new Long [ proIdArray.size ( ) ]   ;
					
					//init gk
					for ( Long proId : proIdArray )	{	 	
						globalKeys.add ( Const.PRO_TYPE_CELLPHONE + StringPool.DASH  + proId ) ;
					}
					
					
					proIdArray.toArray ( proIds) ;						
					ProImage proImage = new ProImage( ) ; 
					proImage.setProIds ( proIds ) ; 
					proImage.setProType ( Const.PRO_TYPE_CELLPHONE ) ;
					List < ProImage > pis = pisi
							.getProImageColorsByProIdsCacheModel ( proImage );
					List proImageColors = null ; 
					for ( CellPhone cp : cps ) { 
						cp.setProImageColors ( null ) ; 
						proImageColors = new ArrayList( ) ; 
						for ( java.util.Iterator < ProImage > iter = pis
								.iterator ( ) ; iter.hasNext ( ) ; ) {
							proImage = iter.next ( );
							if ( proImage.getProId ( )
									.equals ( cp.getProId ( ) ) ) {
								proImageColors.add ( proImage );
								// iter.remove ( ) ;
							}
						}		
						cp.setProImageColors ( proImageColors ) ;
					}
				}
			

				
			
				request.setAttribute ( "dl" , dl ) ;
			}
			
			
			if (  allCellphones != null && allCellphones.size ( ) > 0  ) {
				List< String > globalKeys = new ArrayList< String > ( 5 ) ; 

				for ( CellPhone cp : allCellphones )	{	 	
					globalKeys.add ( Const.PRO_TYPE_CELLPHONE + StringPool.DASH  + cp.getProId ( ) ) ;
				}

				
				if ( globalKeys.size ( ) > 0 ) {
					List< PropertyData > pds =  proPropertySetImp.selectProperty4Search2( globalKeys ) ;
					if ( pds != null ) {
						Map< String  , String > itemKeys = new HashMap< String , String >( pds.size ( ) ) ; 
						for ( PropertyData pd : pds ) { 
							itemKeys.put ( pd.getItemKey ( ) , pd.getItemKey (  ) ) ; 
						}
						request.setAttribute ( "itemKeys" , itemKeys ) ;
					}
					
				}
				else 
					request.setAttribute ( "itemKeys" , new HashMap< String , String >( ) ) ;				
			}

				 	
			request.setAttribute ( "params" , params ) ;
			request.setAttribute ( "searchVo" , cellPhone ) ; 
			request.setAttribute ( "paramsMap" , paramsMap ) ;
			
			logger.info ( "generate CELL PHONE generateAdvParamForm time:" + ( System.currentTimeMillis ( ) - ct ) ) ;			
			return mapping.findForward ( "cellPhones" ) ; 
		}
		
	}	*/
	
	
	@ SuppressWarnings ( "unchecked" )
	public  ActionForward toEditCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		//DIC 
		List< BizOption >  bssOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_CP_CellPhoneBrands_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "brandsOps" , bssOps ) ;
		
		List< BizOption >  bproOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_PUB_STATUS_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bproOps" , bproOps ) ;
		
		BrandServiceImpl brandServiceImpl = ( BrandServiceImpl ) getBean( "brandServiceImpl" ) ;
		Brand brand = new Brand(  ) ; 
		brand.setProType ( Const.PRO_TYPE_CELLPHONE ) ; 
		brand.setWorkflg ( Const.COMMON_STATUS_ENA ) ;
		List brands = brandServiceImpl.getBrandList ( brand ) ; 
		request.setAttribute ( "brands" , brands ) ; 
		
		
		SupplierServiceImpl ssbean = ( SupplierServiceImpl )getBean ( "supplierServiceImpl" ) ;
		ProSuppliers psvo = new ProSuppliers( ) ; 
		psvo.setWorkFlg ( String.valueOf ( Const.COMMON_STATUS_ENA ) ) ;
		psvo.setSupplierPros ( StringPool.COMMA + Const.PRO_TYPE_CELLPHONE + StringPool.COMMA ) ; 
		List< ProSuppliers > proTypes = ssbean.querySuppliersList ( psvo ) ; 
		request.setAttribute ( "proTypes" , proTypes ) ;
		
		return mapping.findForward ( "cellPhone" ) ; 
	}
	
	@ SuppressWarnings ( "unchecked" )
	public  ActionForward cellPhoneIndex( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		
		List< BizOption >  bproOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_PUB_STATUS_KEY ,  false  , CONST.COUNTRY_ZH  ) ;
		request.setAttribute ( "bproOps" , bproOps ) ;

		
		Long proId = cellPhoneForm.getProId ( ) ; 
		CellPhone cellPhone = new CellPhone( ) ; 
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 
		request.setAttribute ( "searchVo" , cellPhone ) ;
		
		cellPhone = sss.getCellPhoneById ( proId ) ; 
		request.setAttribute ( "cellPhone" , cellPhone ) ;
		return mapping.findForward ( "cellPhoneIndex" ) ; 
	}
	
	public  ActionForward pubCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		//
		
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		Long proId = cellPhoneForm.getProId ( ) ; 

		
		String to = "cellPhone.go?method=cellPhoneIndex&proId=" + proId ; 
		
		Byte actStatus = cellPhoneForm.getProActStatus ( ) ; 
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		CellPhone cellPhone = sss.getCellPhoneById ( proId ) ; 
		
		
		if (actStatus != null ) {
			if ( Const.PRO_ACTION_SUB == actStatus ) {
				if ( !NumberUtils.isEmptyOrZero ( proId )  )  //update
					sss.updateCellPhone (  cellPhone ) ; 
				else  //new 
					proId = sss.saveCellPhone (  cellPhone ) ; 				
			}
			else if ( Const.PRO_ACTION_PUB == actStatus ) {
				// check image
				Date offTime = cellPhoneForm.getOffTime ( );
				if ( ( offTime != null && ( new Date ( ).getTime ( )
						- offTime.getTime ( ) >= 0 ) ) ) {
					to += "&error=0";
					return new ActionForward ( to , true );
				}
				
				int size = cellPhone.getProImageColors ( ).size ( );
				if ( size == 0 ) {
					to += "&error=1";
					return new ActionForward ( to , true );
				}
				// check service
				Long ssize = cellPhone.getServicesNums ( );
				if ( ssize == 0 ) {
					to += "&error=1";
					return new ActionForward ( to , true );
				}
				
				
				//check params
				cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED ) ; 
				sss.updateCellPhone ( cellPhone ) ; 
			}
	
			else if ( Const.PRO_ACTION_YULAN == actStatus ) {
				
			}
			else if ( Const.PRO_ACTION_OUT == actStatus ) {
				//只更新 下架状态
				CellPhone odt = sss.getCellPhoneById ( proId ) ; 
				Byte bos = odt.getProOnOffStatus ( ) ; 
				if ( !NumberUtils.isEmptyOrZero ( bos ) &&  Const.PRO_PUB_STATUS_PUBED == bos.byteValue ( )  ) { 
					odt.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT ) ; 
					sss.updateCellPhone ( odt ) ; 						
				}
			}			
		}
		
		return new ActionForward( to  , true ) ; 
	}
	
	
	public  ActionForward editCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		//DIC

		//PARAMS 
		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		ProContentServiceImpl proContentServiceImpl = ( ProContentServiceImpl ) getBean ( "proContentServiceImpl" );
		
		CellPhone cellPhone = new CellPhone( ) ; 
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 
		
		
		cellPhone.setUpdtUser (  getCurrentUser ( request ).getUserId ( ) ) ;
		Long id = cellPhoneForm.getProId ( ) ; 
		// to

		StringBuffer to = new StringBuffer( "cellPhone.go?method=getCellPhone" ) ; 
		//
		Byte actStatus = cellPhoneForm.getProActStatus ( ) ; 
		if (actStatus != null ) {
			if ( Const.PRO_ACTION_SUB == actStatus ) {
				if ( id != null && id.longValue ( ) != 0  )  //update
					sss.updateCellPhone (  cellPhone ) ; 
				else  { //new 
					cellPhone.setCrtUser ( getCurrentUser ( request )
							.getUserId ( ) );
					id = sss.saveCellPhone ( cellPhone );
					to.append ( "&flg=" ).append ( id );
				}
			}
			else if ( Const.PRO_ACTION_PUB == actStatus ) {
				cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED ) ; 
				sss.updateCellPhone ( cellPhone ) ; 
			}
			
			else if ( Const.PRO_ACTION_SUB_CHECK == actStatus ) {
				//CHECK
				//check 
				CellPhone check_vo = sss.getCellPhoneById ( id ) ; 
				Date offTime = cellPhoneForm.getOffTime ( );
				if ( ( offTime != null && ( new Date ( ).getTime ( )
						- offTime.getTime ( ) >= 0 ) ) ) 
					return PorJsonObj.response ( response , PorJsonObj.error ( "offTime" ) );
				

				ProImageServiceImpl pisi = ( ProImageServiceImpl ) getBean( "proImageServiceImpl" ) ;
				ProImage proImage = new ProImage( ) ; 
				proImage.setProId ( id ) ; 
				proImage.setProType ( Const.PRO_TYPE_CELLPHONE ) ;
				List< ProImage > pis =  pisi.getProImageColorsByProIdsCacheModel( proImage ) ;
				
				if ( pis.size ( ) == 0 ) 
					return PorJsonObj.response ( response , PorJsonObj.error ( "color" ) );
				
				// check service
				Long ssize = check_vo.getServicesNums ( );
				if ( ssize == 0 ) 
					return PorJsonObj.response ( response , PorJsonObj.error ( "serivce" ) );
				
				return PorJsonObj.response ( response , PorJsonObj.success (  "!" ) );
			}

			else if ( Const.PRO_ACTION_SUB_PUB == actStatus ) {
				cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
				if ( id != null && id.longValue ( ) != 0 ) // update
					sss.updateCellPhone ( cellPhone );
			}
			
			else if ( Const.PRO_ACTION_YULAN == actStatus ) {
				
			}
			else if ( Const.PRO_ACTION_OUT == actStatus ) {
				//只更新 下架状态
				CellPhone odt = sss.getCellPhoneById ( id ) ; 
				Byte bos = odt.getProOnOffStatus ( ) ; 
				if ( !NumberUtils.isEmptyOrZero ( bos ) &&  Const.PRO_PUB_STATUS_PUBED == bos.byteValue ( )  ) { 
					odt.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT ) ; 
					sss.updateCellPhone ( odt ) ; 						
				}
			}		
			
			//save content
			if ( Const.PRO_ACTION_SUB == actStatus || Const.PRO_ACTION_SUB_PUB == actStatus ) { 
				ProContent content = new ProContent( Byte.valueOf ( Const.PRO_TYPE_CELLPHONE ) , id )  ; 
				content.setContent (  Sentence.replace( cellPhoneForm.getContent ( )  , 0 , "div", "span" , Sentence.IGNORE_CASE )  ) ; 
				proContentServiceImpl.saveAndUpdateProContent ( content ) ;	
			} 
		}
		//Context.indexReload ( ) ; 
		return new ActionForward( to.append ( "&proId=" + id ).toString ( )  , true ); 
	}	
	
	public  ActionForward removeCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		//PARAMS
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		Byte actStatus = cellPhoneForm.getProActStatus ( ) ;
		Date offTime = cellPhoneForm.getOffTime ( ) ;
		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		
		Long[] deleteIds = cellPhoneForm.getDeleteId ( ) ;
		if ( deleteIds != null ) {
			for ( Long deleteId : deleteIds ) {
				CellPhone cellPhone = sss.getCellPhoneById (  deleteId ) ;
				Byte bos = cellPhone.getProOnOffStatus ( ) ; 
				if ( Const.PRO_ACTION_PUB == actStatus ) {
					if ( ! NumberUtils.isEmptyOrZero ( bos )
							&& Const.PRO_PUB_STATUS_PUBED != bos.byteValue ( )  ) {
						if ( offTime == null
								|| ( offTime != null && ( new Date ( )
										.getTime ( )- offTime.getTime ( ) < 0 ) ) ) {
							cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
							cellPhone.setOffTime ( offTime );
							sss.updateCellPhone ( cellPhone );
						}
					}
				}
				else if ( Const.PRO_ACTION_OUT == actStatus ) { 
					if ( ! NumberUtils.isEmptyOrZero ( bos )
							&& Const.PRO_PUB_STATUS_PUBED == bos.byteValue ( ) ) {					
						cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT ) ;  
						sss.updateCellPhone ( cellPhone ) ; 
					}
				}
				else { //delete
					/*
					 * cellPhone.setProOnOffStatus (
					 * Const.PRO_PUB_STATUS_PUB_OUT ) ; cellPhone.setRemoveMark
					 * ( String.valueOf ( Const.COMMON_REMOVE_MARK_Y ) ) ;
					 * sss.updateCellPhone ( cellPhone ) ;
					 */
					sss.removeCellPhone ( deleteId );
				}
				
			}
		}
	
		//Context.indexReload ( ) ; 
		return new ActionForward( "cellPhone.go?method=getCellPhone&pageNum=" + cellPhoneForm.getPageNum ( )  , true ); 
	}		
	
	public  ActionForward toDisTjCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		//PARAMS
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		
		CellPhone cellPhone = new CellPhone( ) ; 
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 
		if ( Boolean.valueOf ( true ).equals ( cellPhone.getSdTj ( ) ) ) {
			cellPhone.setOrderStr ( " e.tjOrder asc ,  e.CRTTIME DESC  " ) ; 
		}
		
		List< CellPhone > cellPhones  = sss.getCellPhoneList ( cellPhone ) ; 
		request.setAttribute ( "cellPhones" , cellPhones ) ; 
		return mapping.findForward ( "toDisTj" ) ;
	}
	

	public ActionForward editDisTjCellPhone( ActionMapping mapping , ActionForm form , 
			HttpServletRequest request , HttpServletResponse response ) throws Exception { 
		//PARAMS
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		String orders = cellPhoneForm.getOrders ( ) ; 

		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;

		if ( !StringUtils.isEmpty ( orders ) && !StringUtils.isBlank ( orders ) ) {
			StringTokenizer st = new StringTokenizer( orders , StringPool.SEMICOLON ) ;
			int count = st.countTokens ( ) ; 
			CellPhone vo = new CellPhone( ) ; 
			for (  int i = 0 ; i <  count ; i ++ ) {
				Long orderId = Long.valueOf ( st.nextToken() );
				vo = sss.getCellPhoneById ( orderId ) ; 
				vo.setTjOrder (  Long.valueOf ( i + 1 ) ) ; 
				sss.updateCellPhone ( vo ) ;
			}
			
		}
		return new ActionForward( "cellPhone.go?method=toDisTjCellPhone&sdTj=1" , true ) ;
	}
	
	
	public  ActionForward toDisCxCellPhone( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		//PARAMS
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		
		CellPhone cellPhone = new CellPhone( ) ; 
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 
		
		if ( Boolean.valueOf ( true ).equals ( cellPhone.getSdCx ( ) ) ) {
			cellPhone.setOrderStr ( " e.cxOrder asc ,  e.CRTTIME DESC  " ) ; 
		}
		
			List< CellPhone > cellPhones  = sss.getCellPhoneList ( cellPhone ) ; 
		request.setAttribute ( "cellPhones" , cellPhones ) ; 
		return mapping.findForward ( "toDisCx" ) ;
	}
	

	public ActionForward editDisCxCellPhone( ActionMapping mapping , ActionForm form , 
			HttpServletRequest request , HttpServletResponse response ) throws Exception { 
		//PARAMS
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		String orders = cellPhoneForm.getOrders ( ) ; 

		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;

		if ( !StringUtils.isEmpty ( orders ) && !StringUtils.isBlank ( orders ) ) {
			StringTokenizer st = new StringTokenizer( orders , StringPool.SEMICOLON ) ;
			int count = st.countTokens ( ) ; 
			CellPhone vo = new CellPhone( ) ; 
			for (  int i = 0 ; i <  count ; i ++ ) {
				Long orderId = Long.valueOf ( st.nextToken() );
				vo = sss.getCellPhoneById ( orderId ) ; 
				vo.setCxOrder (   Long.valueOf ( i + 1 ) ) ; 
				sss.updateCellPhone ( vo ) ;
			}
			
		}
		return new ActionForward( "cellPhone.go?method=toDisCxCellPhone&sdCx=1" , true ) ;
	}
	
	
	public ActionForward searchAdvCellPhone4h( ActionMapping mapping , ActionForm form , 
			HttpServletRequest request , HttpServletResponse response ) throws Exception { 
		//PARAMS
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		String params = cellPhoneForm.getParams ( ) ; 
		StringBuffer sb = new StringBuffer( ) ; 
		String sql = "" ; 
		if ( !StringUtils.isEmpty ( params ) && !StringUtils.isBlank ( params )  ) {
			sb.append ( "ITEM_KEY  IN ( "  ) ; 
			ArgumentTokenizer ats = new ArgumentTokenizer( params , ';' ) ; 
			while (  ats.hasNext ( ) ) {
				String ass = ats.next ( ) ; 
				ArgumentTokenizer as = new ArgumentTokenizer( ass , ':' ) ;
				while( as.hasNext ( ) ) {
					String key = as.next ( ) ; 
					sb.append ( key  ) .append ( "," ) ; 
				}
			}
			sql = sb.substring ( 0 , sb.length ( ) - 1 ) ; 
			sql += " )" ; 
		}		
		
		return mapping.findForward ( "cellPhones" ) ; 
	}
	
	
	//
	@ SuppressWarnings ( "unchecked" )
	public  ActionForward getCellPhones4View( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		long ct = System.currentTimeMillis ( ) ; 
		
		//DIC 
		//DIC 
		List< BizOption >  bcolorOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_Color_KEY ,  false  ,  getSessionLanguage( request ) ) ;
		Map < Byte , String > bcolorNameOpts = new HashMap ( bcolorOps.size ( ) );
		for ( BizOption bo : bcolorOps ) {
			try {
				bcolorNameOpts.put ( Byte.valueOf ( bo.getOptionValue ( ) ) ,
						bo.getOptionName ( ) );
			}
			catch ( Exception exx ) {
			}
		}
		
		request.setAttribute ( "bcolorNameOpts" , bcolorNameOpts ) ;
		
		List< BizOption >  bcolorVOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_Color_HEX_KEY ,  false  ,  getSessionLanguage( request ) ) ;
		//request.setAttribute ( "bcolorVOps" , DictionaryCache.getInstance ( ).convertListToMap ( bcolorVOps ) ) ;
		
		Map < Byte , String > ms = new HashMap ( bcolorVOps.size ( ) );
		for ( BizOption bo : bcolorVOps ) {
			try {
				ms.put ( Byte.valueOf ( bo.getOptionName ( ) ) , bo
						.getOptionValue ( ) );				
			}
			catch ( Exception exx ) {
			}
		}

		request.setAttribute ( "bcolorVOps" , ms ) ;


		List< BizOption >  bpriceOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_CELLPHONE_PRICE ,  false  , getSessionLanguage( request ) ) ;
		request.setAttribute ( "bpriceOps" , bpriceOps ) ;
		
		List< BizOption >  bssOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_SERVICE_PLAN_KEY ,  false  , getSessionLanguage ( request )  ) ;
		request.setAttribute ( "bssOps" , bssOps ) ;
		
		
		
		BrandServiceImpl brandServiceImpl = ( BrandServiceImpl ) getBean( "brandServiceImpl" ) ;
		Brand brand = new Brand(  ) ; 
		brand.setProType ( Const.PRO_TYPE_CELLPHONE ) ; 
		brand.setWorkflg ( Const.COMMON_STATUS_ENA ) ;
		List brands = brandServiceImpl.getBrandList ( brand ) ; 
		request.setAttribute ( "brands" , brands ) ; 
		
		SupplierServiceImpl ssbean = ( SupplierServiceImpl )getBean ( "supplierServiceImpl" ) ;
		ProSuppliers psvo = new ProSuppliers( ) ; 
		psvo.setSupplierPros ( StringPool.COMMA + Const.PRO_TYPE_CELLPHONE + StringPool.COMMA ) ; 
		psvo.setWorkFlg ( String.valueOf ( Const.COMMON_STATUS_ENA ) ) ;
		List< ProSuppliers > proTypes = ssbean.querySuppliersList ( psvo ) ; 
		request.setAttribute ( "proTypes" , proTypes ) ;
		
		ProImageServiceImpl pisi = ( ProImageServiceImpl ) getBean( "proImageServiceImpl" ) ;

		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ;  
		cellPhoneForm.setPageSize (  Const.PAGE_SIZE_Q  ) ;
		CellPhone cellPhone = new CellPhone( ) ; 
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ; 


		 //loads
			//PARAM
			ProPropertySetImp proPropertySetImp = ( ProPropertySetImp )getBean ( "proPropertySetImp" ) ; 
			Map< String , String > paramsMap = new HashMap< String , String > () ; 
			String params = cellPhoneForm.getParams ( ) ;

			String base = "SELECT  distinct( GLOBAL_KEY ) as globalKey FROM " +
					" B_PROPERTYDATA WHERE  ITEM_KEY =";
			String sql = null  ; 
			if ( !StringUtils.isEmpty ( params ) && !StringUtils.isBlank ( params )  ) {
				int flg = 0 ; 
				ArgumentTokenizer ats = new ArgumentTokenizer( params , ';' ) ; 
				while (  ats.hasNext ( ) ) {
					String ass = ats.next ( ) ; 
					ArgumentTokenizer as = new ArgumentTokenizer( ass , ':' ) ;
					while( as.hasNext ( ) ) {
						String key = as.next ( ) ; 
						String value = as.next ( ) ; 
						paramsMap.put ( key , value )	 ;
						flg ++ ; 
						if ( flg == 1 )
							sql = base + "'" + SQLParser.transactSQLInjection (  key ) + "'";
						else
							sql = base   + "'" + SQLParser.transactSQLInjection (  key ) + "'"
									+ " AND GLOBAL_KEY IN ( " + sql + ")";

					}
				}
			}	
			
	
			//generate form
			
			ParamType vo = new ParamType () ; 
		
			//BIS
			
			//生成查询表单
			String as = cellPhoneForm.getAdvsearch ( ) ; 

			if ( SEARCH_ADV.equals ( as ) ) {
				long pst = System.currentTimeMillis ( ) ; 
				ParamServiceImpl psi = ( ParamServiceImpl )getBean( "paramServiceImpl" ) ; 

				List< ParamType > paramTypesTmp = new ArrayList< ParamType > ( ) ; //psi.getParamTypeList (  vo ) ; 		
				vo.setWorkflg ( Const.COMMON_STATUS_ENA ) ; 
				vo.setGlobalKey ( String.valueOf ( Const.PRO_TYPE_CELLPHONE ) ) ;
				//vo.setSearch4q ( true ) ;
				List< ParamType > paramTypeRoots = psi.getRootParamType( vo ) ;
				for ( ParamType paramType : paramTypeRoots ) { 
					if ( paramType.getWorkflg ( ) == Const.COMMON_STATUS_ENA ) {
						List< ParamType  > spt = paramType.getEnableFormChilds4q ( ) ;
						if ( spt != null && spt.size ( ) > 0 )
							paramTypesTmp.add ( paramType ) ;
					}
				}
				request.setAttribute ( "paramvo" , vo ) ;
				request.setAttribute ( "paramTypes" , paramTypeRoots ) ;
				logger.info ( "cell phone generate param search time:" + ( System.currentTimeMillis ( ) - pst ) ) ;				
			}
			
			//初始
					
			DataList dl = null ; 
			List< CellPhone >  allCellphones = null ; 
			List< Long > proIdArray = new ArrayList< Long >( ); 
			if (  !StringUtils.isEmpty ( sql ) && !StringUtils.isBlank ( sql )  ) {
				Map paramsVo = new HashMap( ) ; 
				paramsVo.put ( "GLOBAL" , String.valueOf ( Const.PRO_TYPE_CELLPHONE )   ) ; 
				paramsVo.put ( "PARAMS" , sql ) ; 
				
				long st = System.currentTimeMillis ( ) ; 
				
				List< PropertyData > pds =  proPropertySetImp.selectProperty4Search ( paramsVo ) ; 
				for ( PropertyData pd : pds ) {
					String globalKey = pd.getGlobalKey ( ) ; 
					proIdArray.add ( Long.valueOf ( globalKey.split (  StringPool.DASH  )[ 1 ] ) ) ; 
				}
				logger.info ( "generate search time:" + ( System.currentTimeMillis ( ) - st ) ) ;
			}
			else {
				cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED ) ; 
				if ( !SEARCH_ADV.equals ( as ) ) 
					dl = sss.getCellPhones4View ( cellPhone ) ; 
			
				if ( SEARCH_ADV.equals ( as ) ) { 
					allCellphones = sss.getCellPhones4 ( cellPhone );
					int count = sss.countgetCellPhones4View ( cellPhone ).intValue ( );
					int pn = cellPhone.getPageNum ( );
					int ps = cellPhone.getPageSize ( );
					if ( ( pn - 1 ) * ps  >= allCellphones.size ( ) ) 
						pn = 1 ; 
					dl = new DataList ( allCellphones.subList (
							( ( pn - 1 ) * ps ) , ( ( pn + 1 ) * ps >= allCellphones
									.size ( ) ? allCellphones.size ( ) : ( pn + 1 )
									* ps ) ) ,
					count , ps , pn );					
				}
				
			}
			
			if ( proIdArray.size ( ) >0  ) {
				//
				Long[] proIds = new Long [ proIdArray.size ( ) ]   ;
				proIdArray.toArray ( proIds) ;
				cellPhone.setProIds ( proIds ) ; 
				//dl = sss.getCellPhones4View (  cellPhone ) ; 
				
				
				cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED ) ;
				allCellphones = sss.getCellPhones4 ( cellPhone );
				
				int count = sss.countgetCellPhones4View ( cellPhone ).intValue ( );
				int pn = cellPhone.getPageNum ( );
				int ps = cellPhone.getPageSize ( );
				if ( ( pn - 1 ) * ps  >= allCellphones.size ( ) ) 
					pn = 1 ; 
				
				dl = new DataList ( allCellphones.subList (
						( ( pn - 1 ) * ps ) , ( ( pn + 1 ) * ps > allCellphones
								.size ( ) ? allCellphones.size ( ) : ( pn + 1 )
								* ps ) ) , count , ps , pn );
				
			}
			

				
		
			if ( dl != null ) {
				List< CellPhone > cps = dl.getNowlist ( ) ;

				
				proIdArray = new ArrayList< Long >( ) ; 
				if (  proIdArray.size ( ) == 0 ) {
					for ( CellPhone cp : cps ) { 
						proIdArray.add ( cp.getProId ( ) ) ; 
					}					
				}
			
		
				if ( proIdArray.size ( ) > 0 ) {
					Long[] proIds = new Long [ proIdArray.size ( ) ]   ;

					
					
					proIdArray.toArray ( proIds) ;						
					ProImage proImage = new ProImage( ) ; 
					proImage.setProIds ( proIds ) ; 
					proImage.setProType ( Const.PRO_TYPE_CELLPHONE ) ;
					List < ProImage > pis = pisi
							.getProImageColorsByProIdsCacheModel ( proImage );
					List proImageColors = null ; 
					for ( CellPhone cp : cps ) { 
						cp.setProImageColors ( null ) ; 
						proImageColors = new ArrayList( ) ; 
						for ( java.util.Iterator < ProImage > iter = pis
								.iterator ( ) ; iter.hasNext ( ) ; ) {
							proImage = iter.next ( );
							if ( proImage.getProId ( )
									.equals ( cp.getProId ( ) ) ) {
								proImageColors.add ( proImage );
								// iter.remove ( ) ;
							}
						}		
						cp.setProImageColors ( proImageColors ) ;
					}
				}
			
			
				request.setAttribute ( "dl" , dl ) ;
			}
			if (  allCellphones != null && allCellphones.size ( ) > 0  ) {
				PropertyData ppd = new PropertyData( ) ; 
				ppd.setGlobalKey ( Const.PRO_TYPE_CELLPHONE + StringPool.DASH ) ; 
				List< PropertyData > pds  = proPropertySetImp.selectProperty4Search3( ppd ) ; 
				
				
				if ( pds != null ) {
					Map < String , String > itemKeys = new HashMap < String , String > ( pds.size ( ) );
					for ( PropertyData pd : pds ) {
						for ( CellPhone cp : allCellphones ) {
							if ( ( Const.PRO_TYPE_CELLPHONE + StringPool.DASH + cp
									.getProId ( ) )
									.equals ( pd.getGlobalKey ( ) ) )
								itemKeys.put ( pd.getItemKey ( ) , pd
										.getItemKey ( ) );
						}
						
					}
					request.setAttribute ( "itemKeys" , itemKeys );
				} else
					request.setAttribute ( "itemKeys" ,
							new HashMap < String , String > ( ) );		
			}			
				 	
			request.setAttribute ( "params" , params ) ;
			request.setAttribute ( "searchVo" , cellPhone ) ; 
			request.setAttribute ( "paramsMap" , paramsMap ) ;	
				
		logger.info ( "cell Phone 4 views loads " + ( System.currentTimeMillis ( ) - ct ) ) ; 
		
		if ( SEARCH_ADV.equals ( as ) ) 
			return mapping.findForward ( "advcellPhones4View" ) ; 
		else 
			return mapping.findForward ( "cellPhones4View" ) ; 
		
	}
	

	@ SuppressWarnings ( "unchecked" )
	public  ActionForward getCellPhone4View( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response ) throws Exception {
		long currentTime = System.currentTimeMillis ( ) ;
		response.setContentType ( "text/html;charset="
				+ AppContext.getFrameWorkPropertiesBean ( ).getCharSet ( ) );
		//DIC 
		List< BizOption >  bcolorOps = DictionaryCache.getInstance ( ).listBizOptions( Const.DIC_B_PRO_Color_KEY ,  false  ,  getSessionLanguage( request ) ) ;
		Map < Byte , String > bcolorNameOpts = new HashMap ( bcolorOps.size ( ) );
		for ( BizOption bo : bcolorOps ) {
			try {
				bcolorNameOpts.put ( Byte.valueOf ( bo.getOptionValue ( ) ) ,
						bo.getOptionName ( ) );
			}
			catch ( Exception exx ) {
			}
		}
		request.setAttribute ( "bcolorNameOpts" , bcolorNameOpts ) ;
		
		
		//BIS
		CellPhoneServiceImpl sss = ( CellPhoneServiceImpl )getBean ( "cellPhoneServiceImpl" ) ;
		ProImageServiceImpl pisi = ( ProImageServiceImpl ) getBean( "proImageServiceImpl" ) ;
		ProContentServiceImpl proContentServiceImpl = ( ProContentServiceImpl )getBean( "proContentServiceImpl" ) ; 		
		
		CellPhoneForm cellPhoneForm = ( CellPhoneForm ) form ; 
		CellPhone cellPhone = new CellPhone( ) ; 
		PropertyUtils.copyProperties ( cellPhone , cellPhoneForm ) ;
		
		Long proId = cellPhone.getProId ( ) ; 
		
		String flg4boc = cellPhoneForm.getFlg4boc ( ) ; 
		//

		boolean showModal = false ;
		if ( cellPhone.getShowModal ( ) != null
				&& cellPhone.getShowModal ( ) )
			showModal = true ; 
	

		if ( Const.FLG_FOR_GET_BASEINFO.equals ( flg4boc ) ) {
			if ( NumberUtils.isEmptyOrZero ( proId ) )
				return mapping.findForward ( "proout" );
			
			//
			//DIC

			//
			if ( showModal )
				cellPhone = sss.getCellPhoneById ( proId );
			else
				cellPhone = sss.getBaseCellPhoneInfoById4View ( proId );

			if ( cellPhone == null )
				return mapping.findForward ( "proout" );
			
			ProImage proImage = new ProImage ( proId , Const.PRO_TYPE_CELLPHONE );
			
			
			if ( showModal ) { // 预览 颜色
				List < ProImage > pis = pisi
					.getProImageColorsByProIdsCacheModel ( proImage );
				cellPhone.setProImageColors( pis ) ;
			} 
			
			//设置颜色
			if ( cellPhoneForm.getColor ( ) != null )
				proImage.setColor ( cellPhoneForm.getColor ( ) );
			else {
				List < ProImage > colors = pisi
						.getProImageColorsByProIdsCacheModel ( proImage );
				if ( colors != null && colors.size ( ) > 0 ) {
					proImage.setColor ( colors.get ( 0 ).getColor ( ) );
				}
				else 
					return mapping.findForward ( "proout" );
			}
			
			request.setAttribute ( "color" , proImage.getColor ( ) ) ; 
				
			//取商品对应的颜色图片
			List < ProImage > proImages = pisi
					.getProImagesByProIdaTypeCacheModel ( proImage );
			if ( proImages != null && proImages.size ( ) == 0 ) 
				return mapping.findForward ( "proout" );
			else
				cellPhone.setProImages ( proImages );

			logger.info ( "load base cellPhone 4 views time:"
					+ ( System.currentTimeMillis ( ) - currentTime ) );

	
			request.setAttribute ( "vo" , cellPhone ) ; 
			//
			return mapping.findForward ( "cellPhone4View" ) ; 
		}
		

		if ( Const.FLG_FOR_GET_CONTENTINFO.equals ( flg4boc ) )  {
			ProContent pcontent = proContentServiceImpl.getProContentCacheModel (  
					new ProContent( Byte.valueOf ( Const.PRO_TYPE_CELLPHONE ) ,  proId  )  ) ;
			if ( pcontent != null ) 
				return PorJsonObj.response ( response , PorJsonObj
						.getProContentJSONObject ( pcontent.getContent ( ) ).toString ( ) );
			else 
				return PorJsonObj.response ( response , PorJsonObj
						.getProContentJSONObject ( "" ).toString ( ) );
		}
		
		return PorJsonObj.response ( response , PorJsonObj.error (
				CONST.COUNTRY_ZH ).toString ( ) );
		
	}
	

}
